package com.ysx.oa.clazz.controller;

import com.ysx.oa.clazz.bean.ClazzStudentTeacherBean;
import com.ysx.oa.clazz.entity.ClazzStudentTeacherEntity;
import com.ysx.oa.clazz.service.ClazzStudentTeacherService;
import com.ysx.oa.role.bean.RoleBean;
import com.ysx.oa.user.bean.UserBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 李伟伟
 * @date 2021/11/23 16:32
 */
@RestController
@RequestMapping("/clazzStudentTeacher")
public class ClazzStudentTeacherController {
    @Autowired
    private ClazzStudentTeacherService clazzStudentTeacherService;


    // http://localhost:8080/kaoqin/clazzStudentTeacher/delete
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    public  Map<String ,Object> delete(@RequestBody List<Integer> userId){
        Map<String, Object> map = new HashMap();
        clazzStudentTeacherService.deleteStudent(userId);
        map.put("code",200);
        map.put("message","success");
        map.put("data",null);
        return map;
    }




    // http://localhost:8080/kaoqin/clazzStudentTeacher/findAll
    @RequestMapping(value = "/findAll",method = RequestMethod.POST)
    public  Map<String ,Object> findAllStudent(){
        Map<String, Object> map = new HashMap();
        List<ClazzStudentTeacherEntity> all = clazzStudentTeacherService.findAll();
        map.put("code",200);
        map.put("message","success");
        map.put("data",all);
        return map;
    }



    // http://localhost:8080/kaoqin/clazzStudentTeacher/addStudent
    @RequestMapping(value = "/addStudent",method = RequestMethod.POST)
    public  Map<String ,Object> addStudent(@RequestBody ClazzStudentTeacherBean bean){
        Map<String, Object> map = new HashMap();
        Integer id = clazzStudentTeacherService.addStudent(bean);
        map.put("code",200);
        map.put("message","success");
        map.put("data",id);
        return map;
    }


    // http://localhost:8080/kaoqin/clazzStudentTeacher/addTeacher
    @RequestMapping(value = "/addTeacher",method = RequestMethod.POST)
    public  Map<String ,Object> addTeacher(@RequestBody ClazzStudentTeacherBean bean){
        Map<String, Object> map = new HashMap();
        clazzStudentTeacherService.addTeacher(bean);
        map.put("code",200);
        map.put("message","success");
        map.put("data",null);
        return map;

    }


    //http://localhost:8080/kaoqin/clazzStudentTeacher/findStudent
    @RequestMapping(value = "/findStudent",method = RequestMethod.POST)
    public  Map<String ,Object> findStudent(@RequestBody RoleBean roleBean){
        Map<String, Object> map = new HashMap();
        List<UserBean> id = clazzStudentTeacherService.findStudentOrTeacherByNotClass(roleBean);
        map.put("code",200);
        map.put("message","success");
        map.put("data",id);
        return map;
    }


}
